﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ClientServer.Common
{
    public class RandomUtils
    {
        public static  double NextDouble(double minValue, double maxValue)
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            int iSeed = BitConverter.ToInt32(buffer, 0);

            Random ran = new Random(iSeed);
            return ran.NextDouble() * (maxValue - minValue) + minValue;
        }

        public static double NextDouble(double minValue, double maxValue, int decimalPlace)
        {

            byte[] buffer = Guid.NewGuid().ToByteArray();
            int iSeed = BitConverter.ToInt32(buffer, 0);

            Random ran = new Random(iSeed);

            double randNum = ran.NextDouble() * (maxValue - minValue) + minValue;
            return Convert.ToDouble(randNum.ToString("f" + decimalPlace));
        }




        /// <summary>
        /// 生成整数
        /// </summary>
        /// <param name="minValue"></param>[min,max)，前开后闭
        /// <param name="maxValue"></param>
        /// <returns></returns>
        public static int NextInt(int minValue, int maxValue)
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            int iSeed = BitConverter.ToInt32(buffer, 0);

            Random ran = new Random(iSeed);
            return ran.Next(minValue, maxValue);

        }


        /// <summary>
        /// 根据权重创建受控的随机数
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="weights"></param>
        /// <returns></returns>
        ////public static int CreateControlledRandom(List<int> datas, List<ushort> weights)
        ////{
           
        ////    //随机数生成器
        ////    byte[] buffer = Guid.NewGuid().ToByteArray();
        ////    int iSeed = BitConverter.ToInt32(buffer, 0);

        ////    System.Random rand = new System.Random(iSeed);
           
        ////    int[] rands = RandomControlledController.Instance.ControllerRandomExtract(rand, datas, weights);
        ////    return rands[0];
        ////}
    }
}